import request from "../../utils/request";
import store from "../../store";
export function getChatList({
	pageNum,
	pageSize,
	dialogueId
}) {

	return request({
		'url': '/solution/chat/AppList',
		headers: {
			isToken: true
		},
		'method': 'get',
		'params': {
			pageNum,
			pageSize,
			dialogueId
		}
	})
}

export function Communication(dialogueId) {

	const now = formatDateTime(new Date())
	return request({
		'url': '/solution/chat/communication',
		headers: {
			isToken: true
		},
		'method': 'get',
		'params': {
			now,
			dialogueId
		}
	})
}

function formatDateTime(date) {
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 确保月份是两位数
    const day = date.getDate().toString().padStart(2, '0');          // 确保天数是两位数
    const hours = date.getHours().toString().padStart(2, '0');       // 确保小时是两位数
    const minutes = date.getMinutes().toString().padStart(2, '0');   // 确保分钟是两位数
    const seconds = date.getSeconds().toString().padStart(2, '0');   // 确保秒数是两位数

    // 拼接成所需格式
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}


export function addChat({
	dialogueId,
	dialogueContent,
}) {

	return request({
		'url': '/solution/chat/app',
		headers: {
			isToken: true
		},
		'method': 'post',
		'data': {
			dialogueId,
			dialogueContent,
			userType: 1,
			userId: store.getters.id
		}
	})
}